# !/usr/bin/env python
# coding=utf-8
# @Time    : 2017/12/20 15:24
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/wx_server_prototype.git
# @File    : my_redis.py
# @Software: PyCharm
# @Version: 3.5.4
from app import redis_store
from configs import current_config
import json


def del_data(key):
	return redis_store.delete(current_config.REDIS_KEY_PREFIX+key)


def get_data(key):
	data = redis_store.get(current_config.REDIS_KEY_PREFIX+key)
	if data:
		return bytes.decode(data)
	else:
		return None


def set_data(key, data, expire=current_config.REDIS_DEFAULT_EXPIRE):
	if isinstance(data, dict):
		redis_store.set(current_config.REDIS_KEY_PREFIX+key, json.dumps(data, ensure_ascii=False), expire)
	elif isinstance(data, list):
		redis_store.set(current_config.REDIS_KEY_PREFIX+key, json.dumps(data, ensure_ascii=False), expire)
	else:
		redis_store.set(current_config.REDIS_KEY_PREFIX+key, data, expire)